package com.maolong.springbootstartordercenter.controller;

import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StartController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @RequestMapping("/start")
    public String test(){

        /**
         *
         */
        CorrelationData data=new CorrelationData("123");

        /**
         * 消息的发送前如何处理的策略
         * setExpiration 设置消息的过期时间
         * setDelay 设置消息的延迟时间
         *
         */
        MessagePostProcessor processor=(message)->{
            message.getMessageProperties().setExpiration("5000");
            return message;
        };

        /**
         * 没使用策略，直接进行了发送，绑定了交换机以及路由策略和消息内容
         */
        rabbitTemplate.convertAndSend("spring-topicExchange","storage.center","订单消息");
        rabbitTemplate.convertAndSend("spring-topicExchange","pay.center","订单消息");
        System.out.println("hahahahahha");
        return "ok";
    }
}
